package cn.sciento.transfer.infra.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import cn.sciento.transfer.domain.entity.ConsumerEvent;
import cn.sciento.transfer.infra.datasource.sql.FieldBuilder;
import org.springframework.jdbc.core.RowMapper;

public class JdbcConsumerEventMapper implements RowMapper<ConsumerEvent> {
  public ConsumerEvent mapRow(ResultSet resultSet, int i) throws SQLException {
    ConsumerEvent consumerEvent = new ConsumerEvent();
    consumerEvent.setEventId(Long.valueOf(resultSet.getLong(FieldBuilder.formatFieldToColumn("eventId"))));
    consumerEvent.setSourceKeyId(Long.valueOf(resultSet.getLong(FieldBuilder.formatFieldToColumn("sourceKeyId"))));
    consumerEvent.setProduceTime(resultSet.getTimestamp(FieldBuilder.formatFieldToColumn("produceTime")));
    consumerEvent.setProcessMsg(resultSet.getString(FieldBuilder.formatFieldToColumn("processMsg")));
    consumerEvent.setMessages(resultSet.getString(FieldBuilder.formatFieldToColumn("messages")));
    consumerEvent.setProcessStatus(resultSet.getString(FieldBuilder.formatFieldToColumn("processStatus")));
    consumerEvent.setSourceTenantId(Long.valueOf(resultSet.getLong(FieldBuilder.formatFieldToColumn("sourceTenantId"))));
    consumerEvent.setProcessTime(resultSet.getTimestamp(FieldBuilder.formatFieldToColumn("processTime")));
    consumerEvent.setSourceTable(resultSet.getString(FieldBuilder.formatFieldToColumn("sourceTable")));
    consumerEvent.setSourceService(resultSet.getString(FieldBuilder.formatFieldToColumn("sourceService")));
    consumerEvent.setEventType(resultSet.getString(FieldBuilder.formatFieldToColumn("eventType")));
    consumerEvent.setObjectVersionNumber(Long.valueOf(resultSet.getLong(FieldBuilder.formatFieldToColumn("objectVersionNumber"))));
    consumerEvent.setTargetService(resultSet.getString(FieldBuilder.formatFieldToColumn("targetService")));
    consumerEvent.setTargetDs(resultSet.getString(FieldBuilder.formatFieldToColumn("targetDs")));
    consumerEvent.setTargetDsId(Long.valueOf(resultSet.getLong(FieldBuilder.formatFieldToColumn("targetDsId"))));
    consumerEvent.setTargetDb(resultSet.getString(FieldBuilder.formatFieldToColumn("targetDb")));
    consumerEvent.setTargetTable(resultSet.getString(FieldBuilder.formatFieldToColumn("targetTable")));
    return consumerEvent;
  }
}
